package com.lovo.web.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lovo.web.bean.ProductBean;
import com.lovo.web.bean.ProductListingReviewBean;
import com.lovo.web.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("product")
@RestController
public class ProductController {

    @Autowired
    private IProductService service;

    @GetMapping("findProductTypeLst/{type}/{pageNO}/{isPromotion}")
    public IPage<ProductBean> findProductTypeLst(@PathVariable("type") String type, @PathVariable("pageNO") int pageNO, @PathVariable("isPromotion") int isPromotion) {
        return service.findProductTypeLst(type, pageNO, isPromotion);
    }

    @GetMapping("updateProductStatus")
    public void updateProductStatus(String productName, int status) {
        service.updateProductStatus(productName, status);
    }

    @PostMapping("updateProductStatusSelf")
    public String updateProductStatusSelf(@RequestBody ProductBean productBean) {
        //调用后端接口修改商品状态
        service.updateProductStatusSelf(productBean);
        return "ok";
    }

    @GetMapping("findByProductName")
    public ProductBean findByName(String productName) {
        return service.findByName(productName);
    }

    @GetMapping("findTypeLst")
    public List<ProductBean> findTypeLst() {
        return service.findTypeLst();
    }

    @GetMapping("daishangjiaProduct")
    public Object daishangjiaProduct(Integer pageNO) {
        return service.daishangjiaProduct(pageNO);
    }

    @GetMapping("inKu/{productName}/{specs}/{num}")
    public boolean inKu(@PathVariable("productName") String productName, @PathVariable("specs") String specs, @PathVariable("num") int num) {
        service.inku(productName, specs, num);
        return true;
    }

    @RequestMapping("findByKeyWord/{pageNO}/{keyWord}")
    public IPage<ProductBean> findByKeyWord(@PathVariable("pageNO") int pageNO, @PathVariable("keyWord") String keyWord) {
        return service.findByKeyWord(pageNO, keyWord);
    }

    @RequestMapping("updateIsPromotion")
    public boolean updateIsPromotion(@RequestParam("productNames") List<String> productNames, @RequestParam("discount") float discount) {
        service.updateIsPermission(productNames, discount);
        return true;
    }

    @RequestMapping("showSeason/{name}")
    public ProductListingReviewBean showSeason(@PathVariable("name") String name){
        return service.findPLRByName(name);
    }
}
